<template>
  <div>
    <Spin :spinning="exportLoading" tip="Loading...">
       <el-radio v-model="financeCancelType" label="24231001">清理未结算订单</el-radio>
       <el-radio v-model="financeCancelType" label="24231002">放弃销售订单</el-radio>

      <FormPanel ref="from" :list="formList" @formChange="changeHandle" :isSubmitBtn="false" :collapse="false" labelWidth="110" />

      <div style="height: 47px"></div>
      <div
        :style="{
          position: 'absolute',
          left: 0,
          bottom: 0,
          right: 0,
          zIndex: 9,
          borderTop: '1px solid #e9e9e9',
          padding: '10px 20px',
          background: '#fff',
          textAlign: 'right',
        }"
      >
        <el-button @click="closeDrawer(1)">取 消</el-button>
        <!-- <el-button @click="closeDrawer(2)" type="primary">确 定</el-button> -->
        <multiuse-button type="primary" :click="closeDrawer.bind(this, 2)">确 定</multiuse-button>
      </div>
    </Spin>
  </div>
</template>
<script>
import { postrejectCheck } from '@/api/omSale/OrderManagement/OrderAuditConfirm';
export default {
  data() {
    this.saveData = null;
    return {
      formList: this.createdFrom(),
      exportLoading: false,
      financeCancelType: 24231001
    };
  },
  components: {},
  props: ['list'],
  methods: {
    createdFrom() {
      return [
        {
          type: 'TEXT_AREA',
          label: '作废原因',
          fieldName: 'checkRamark',
          placeholder: '请输入',
          selfCols: 3,
          rules: [{ required: true, message: '请输入', trigger: 'blur' }],
        },
      ];
    },
    changeHandle(val) {
      this.saveData = val;
    },
    async closeDrawer(type) {
      if (type == 1) {
        this.$emit('close');
      } else {
        this.$refs.from.SUBMIT_FORM();
        if (this.saveData!==null) {
          this.exportLoading = true;
          let json = JSON.parse(JSON.stringify(this.saveData));
          let arr = [];
          this.list.map((x) => {
            arr.push(x.id);
          });
          json.ids = arr;
          json.financeCancelType=this.financeCancelType;
          console.log(json)
          let res = await postrejectCheck(json);
          this.exportLoading = false;
          if (res.resultCode == 200) {
            let total = res.data.total;
            let errorTotal = res.data.errorTotal;
            let error = res.data.error;
            this.$notify({
              title: '作废状态',
              message: '作废状态：作废' + total + '条,失败' + errorTotal + '条,失败列表' + error,
              type: 'success',
            });
            // this.$notify({
            //   title: '作废状态',
            //   message: '作废成功',
            //   type: 'success',
            // });
            this.$emit('close', json);
          } else {
            this.exportLoading = false;
            this.saveData = null;
          }
        }
      }
    },
  },
};
</script>
